<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="<s:url value="/css/style.css"/>" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript" src="<s:url value="/js/common.js"/>"></script>
		<script type="text/javascript"
			src="<s:url value="/js/jquery-1.3.2.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.bgiframe.min.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.ajaxQueue.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/thickbox-compressed.js"/>"></script>
		<script type='text/javascript'
			src="<s:url value="/js/autocomplete/jquery.autocomplete.js"/>"></script>
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/jquery.autocomplete.css"/>" />
		<link rel="stylesheet" type="text/css"
			href="<s:url value="/js/autocomplete/thickbox.css"/>" />
		<script type="text/javascript" src="<s:url value="/js/jquery-ui.js"/>"></script>
		<link href="<s:url value="/css/jquery.css"/>" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript" src="<s:url value="/js/jquery.form.js"/>"></script>
		<script type="text/javascript" src="<s:url value="/js/jquery.validate.js"/>"></script>
		<script type="text/javascript" src="<s:url value="/js/ajaxfileupload.js"/>"></script>
		<script type="text/javascript">
		function doSubmit() {
			// here is validate form .
			var leadsType = $('#leadsType').val();
			var school = $('#school').val();
			if(leadsType=='CarOwner'){
				if(school==''){
					$('#shoolEroor').html('Please select a school.').addClass('error').show();
					return false;
				}
			}
			if(!$('#file').val()){
				alert('Please select a excel file.'); return ;
			}
			doBeforeSubmit();
			$('#editForm').submit();
		}
		function goBack() {
			location.href = '<s:url value="/customer/Leads/list"/>';
		}
		
		$( function() {
			if($.trim($('#msg').val())!=''){
				var msg = eval('('+$('#msg').val()+')');
				alert('success: '+msg.sucess +'  failure: '+ msg.failure +' . import ok.');
			}
			$('#shoolEroor').hide();
		    $('#editForm').validate();
			$('#initVisitTime').datepicker( {
				dateFormat :'yy-mm-dd'
			});
			if ($.trim($('#result').text()) != '') {
				popupDiv('pop-div');
			};
			 $("#selMarketingPlan").autocomplete("<s:url value="/marketing/autoCompleteAjaxWithTeam.action"/>", {
			             width: 300,
			             minChars:2, //几个字
			             mastMatch:true,
			             selectFirst: false,
			             max:  40,
			         	   formatItem: function(row, i, max) {
			         	      var d=eval("("+row+")");
				      return  d.name;
			      },
			      formatMatch: function(row, i, max) {
			         var d=eval("("+row+")");
					     return d.name;
			      },
			      formatResult: function(row) {
			         var d=eval("("+row+")");
				     return d.name;
			   	       }
			          });
			  	$("#selMarketingPlan").result(function(event, data, formatted) {
			         	      var d=eval("("+data+")");
			          $("#selMarketingPlanId").val(d.id);
			          $("#selAdChannelId").val(d.aid);
			          $("#selAdChannel").val(d.aname);
			          $('#selMarketPolicy').val( d.pid );
			   	});
			  	$("#selAdChannel").autocomplete("<s:url value="/data/AdChannel/autoCompleteAjax.action"/>", {
			             width: 300,
			             minChars:2, //几个字
			             mastMatch:true,
			             selectFirst: false,
			             max:  20,
			         	   formatItem: function(row, i, max) {
			         	      var d=eval("("+row+")");
				      return  d.name;
			         },
			      formatMatch: function(row, i, max) {
			         var d=eval("("+row+")");
					     return d.name;
			      },
			      formatResult: function(row) {
			         var d=eval("("+row+")");
				     return d.name;
			   	       }
			          });
			          $("#selAdChannel").result(function(event, data, formatted) {
			         	      var d=eval("("+data+")");
			          $("#selAdChannelId").val(d.id);
			          });
			          $("#selPTE").autocomplete("<s:url value="/data/PTE/autoCompleteAjax.action"/>", {
			             width: 300,
			             minChars:2, //几个字
			             mastMatch:true,
			             selectFirst: false,
			             max:  20,
			         	   formatItem: function(row, i, max) {
			         	      var d=eval("("+row+")");
				      return  d.name+" "+d.wno;
			         },
			      formatMatch: function(row, i, max) {
			         var d=eval("("+row+")");
					     return d.name+" "+d.wno;
			      },
			      formatResult: function(row) {
			         var d=eval("("+row+")");
				     return d.name;
			   	       }
			   });
	          $("#selPTE").result(function(event, data, formatted) {
	         	      var d=eval("("+data+")");
	                 $("#selPTEId").val(d.id);
	          });
	          $("#selPTELead").autocomplete("<s:url value="/data/PTE/autoCompleteAjax.action"/>", {
			             width: 300,
			             minChars:2, //几个字
			             mastMatch:true,
			             selectFirst: false,
			             max:  20,
			         	   formatItem: function(row, i, max) {
			         	      var d=eval("("+row+")");
				      return  d.name+" "+d.wno;
			         },
			      formatMatch: function(row, i, max) {
			         var d=eval("("+row+")");
					     return d.name+" "+d.wno;
			      },
			      formatResult: function(row) {
			         var d=eval("("+row+")");
				     return d.name;
			   	       }
			   });
	          $("#selPTELead").result(function(event, data, formatted) {
	         	      var d=eval("("+data+")");
	                  $("#selPTELeadId").val(d.id);
	          });
		});
		function changeSchool(obj){
			 if(obj.selectedValue == 'CarOwner'){
				$('#schoolTr').show();
			 }else{
				 $('#schoolTr').hide();
			 }
		}
		function doBeforeSubmit(){
			$('#marketingPlan_hd').val($('#selMarketingPlanId').val()); 
			$('#marketingpolicy_hd').val($('#selMarketPolicy').val());
			$('#adChannel_hd').val($('#selAdChannelId').val());
			$('#leadsSource_hd').val($('#leadsSource').val());
			$('#leadsType_hd').val($('#leadsType').val());
			$('#school_hd').val($('#school').val());
		}
	</script>
	<title><s:text name="system.title" /></title>
	</head>
	<body>
		<s:include value="/common/up.jsp"></s:include>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td class="box">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td id="tag-over">
								<span id="tag-over">Leads</span>
							</td>
							<td class="tab3-line" width="90%">
								&nbsp;
							</td>
						</tr>
					</table>
					<s:form action="Import/doImport" namespace="/file" method="post"
						id="editForm" name="editForm" enctype="multipart/form-data">
						 <s:hidden name="marketingPlan_hd" id="marketingPlan_hd"></s:hidden>
						 <s:hidden name="marketingpolicy_hd" id="marketingpolicy_hd"></s:hidden>
						 <s:hidden name="adChannel_hd" id="adChannel_hd" ></s:hidden>
						 <s:hidden name="leadsSource_hd" id="leadsSource_hd" ></s:hidden>
						 <s:hidden name="leadsType_hd" id="leadsType_hd" ></s:hidden>
						 <s:hidden name="school_hd" id="school_hd" ></s:hidden>
						 <s:hidden name="msg" id="msg" />
						 <table width="100%" border="0" cellpadding="3" cellspacing="1"
							class="margin">
							<tr>
								<td align="right" class="tablecolour5">
									Marketing Plan:
								</td>
								<td class="tablecolour5" colspan="3">
									<s:textfield id="selMarketingPlan" name="marketingPlan.name"  
										cssClass="input2" size="40" />
									<s:hidden id="selMarketingPlanId" name="marketingPlan.id" />
								</td>
							</tr>
							<tr>
								<td align="right" class="tablecolour5">
									Marketing Policy<font color="red">*</font>:
								</td>
								<td class="tablecolour5">
									<s:select id="selMarketPolicy" name="marketingPolicy.id"
										headerValue="--select--" headerKey="" cssClass="required"
										list="marketingPolicyList"  />
								</td>
								<td align="right" class="tablecolour5">
									Ad Channel<font color="red">*</font>:
								</td>
								<td class="tablecolour5">
									<s:textfield id="selAdChannel" name="adChannel.name"  
										cssClass="input2 required" size="40" />
									<s:hidden id="selAdChannelId" name="adChannel.id" />
								</td>
							</tr>
							<tr>
								<td align="right" class="tablecolour5">
									Leads Source<font color="red">*</font>:
								</td>
								<td class="tablecolour5">
									<s:select name="leadsSource" headerValue="--select--" cssClass="input2 required"
										headerKey="" list="@com.ef.constant.ELeadsSource@values()"
										listKey="name()" id="leadsSource" />
								</td>
								<td align="right" class="tablecolour5">
									Leads Type<font color="red">*</font>:
								</td>
								<td class="tablecolour5">
									<s:select name="leadsType" headerValue="--select--" cssClass="input2 required"
										headerKey="" list="@com.ef.constant.ELeadsType@values()"
										listKey="name()" id="leadsType"   onchange="javascript:changeSchool(this)" />
								</td>
							</tr>
							<tr id="schoolTr"> 
								<td align="right" class="tablecolour5">
									School:
								</td>
								<td class="tablecolour5">
									<s:select id="school" headerValue="----select---" headerKey="" name="school.id" list="schoolList" /><label id="shoolEroor"></label>
								</td>
								<td align="left" class="tablecolour5" colspan="2">
									 
								 <s:file name="file" id="file"></s:file>
									 
								</td>
							</tr>
							<tr>
								<td align="center" colspan="4" height="50" class="tablecolour5">
									<input type="button" class="btn1" value="Import"
										onclick="doSubmit();" />
									<input name="goback" type="button" class="btn1" value="Go Back"
										onClick="history.back(-1)" />
								</td>
							</tr>
						</table>
					</s:form>
				</td>
			</tr>
		</table>
		<s:include value="/common/down.jsp"></s:include>
		<div id='pop-div' style="width: 300px;" class="pop-box">
			<s:include value="/common/confirm.jsp"></s:include>
		</div>
	</body>
</html>